package message;

import model.RoomInfo;
import socket.ChessServer;

/**
 * 放置棋子报文.
 *
 * @author 张紘溢
 */
public class MovePiecesMessage extends BaseMessage {
    private int roomId;
    private boolean isLeft;
    private int[][] nowTable;
    private boolean backChess = false;
    private int x;
    private int y;

    public MovePiecesMessage(int roomId, boolean isLeft, int[][] nowTable, boolean backChess, int x, int y) {
        this.roomId = roomId;
        this.isLeft = isLeft;
        this.nowTable = nowTable;
        this.backChess = backChess;
        this.x = x;
        this.y = y;
    }

    @Override
    public void sendToServer() {
        System.out.println(nowTable[0][0]);
        RoomInfo roomInfo = ChessServer.getInstance().getRooms().get(roomId);
        if (isLeft) {
            ServerMovePiecesMessage serverMovePiecesMessage = new ServerMovePiecesMessage(nowTable, backChess, x, y);
            ChessServer.getInstance().sendMsgToClient(serverMovePiecesMessage, roomInfo.getRightPlayer());
        } else {
            ServerMovePiecesMessage serverMovePiecesMessage = new ServerMovePiecesMessage(nowTable, backChess, x, y);
            ChessServer.getInstance().sendMsgToClient(serverMovePiecesMessage, roomInfo.getLeftPlayer());
        }
    }

    @Override
    public void selfExecute() {

    }
}
